package com.freedom.auth.controller;

import com.freedom.auth.service.IPermissionService;
import com.freedom.auth.domain.Permission;
import com.freedom.auth.query.PermissionQuery;
import com.freedom.base.util.AjaxResult;
import com.freedom.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author freedom
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    public IPermissionService permissionService;

    /**
     * 高级查询数据
     *
     * @param query 查询权限
     * @return PageList 权限对象
     */
    @PutMapping
    public AjaxResult queryPage ( @RequestBody PermissionQuery query ) {
        try {
            PageInfo<Permission> pageInfo = permissionService.queryPage(query);
            return AjaxResult.success(pageInfo, "分页查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("分页查询失败！" + e.getMessage());
        }
    }

    @GetMapping
    public AjaxResult getAll (  ) {
        try {
            List<Permission> list = permissionService.getAll();
            return AjaxResult.success(list, "查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("查询失败！" + e.getMessage());
        }
    }
}
